import datetime
from haystack import indexes
from goods.models import SKU


class SKUIndex(indexes.SearchIndex, indexes.Indexable):
    # 配置字段
    text = indexes.CharField(document=True, use_template=True)

    price = indexes.DecimalField(model_attr='price')
    name = indexes.CharField(model_attr='name')
    default_image_url = indexes.CharField(model_attr='default_image_url')

    # 配置在哪个模型类搜索
    def get_model(self):
        return SKU

    # 指定数据集
    def index_queryset(self, using=None):
        """
        using when the entire index for model is update
        :param using:
        :return:
        """
        return self.get_model().objects.filter(is_launched=True)


